import { Controller, Get, Post, Body, HttpCode, Request, Response, Query, Header } from '@nestjs/common';
import { UserService as Service } from '../services/user.service';


@Controller('user')
export class UserController {

    constructor(private readonly service: Service) { }

    /**
     * 查询列表
     * @param query 
     */
    @Get()
    async getAll(@Query() query): Promise<any> {
        return this.service.findAll({});
    }

    /**
    * 按条件查询
    */
    @Post('/findwhere')
    findWhere(@Body() body): Promise<any> {
        return this.service.findWhere(body);
    }

    /**
    * 判断用户是否存在
    */
    @Post('/hasuser')
    hasUser(@Body() body): Promise<any> {
        return this.service.hasUser(body);
    }

    /**
     * 添加
     */
    @Post('/add')
    async add(@Body() body): Promise<any> {
        return this.service.add(body);
    }

    /**
     * 修改
     */
    @Post('/update')
    async update(@Body() body, @Request() res): Promise<any> {
        let token = res.headers.authorization;
        return this.service.update(body);
    }

    /**
     * 删除
     */
    @Post('/delete')
    async delete(@Body() body): Promise<any> {
        return this.service.delete(body);
    }
}
